var pageii = null;
var grid = null;
$(function() {
	grid = lyGrid({
		pagId : 'paging',
		l_column : [ {
			colkey : "id",
			name : "id"
		},{
			colkey : "Record_Date",
			name : "记录日期",
			renderData : function(rowindex,data, rowdata, column) {	
				if(data!=''){
					return new Date(data).format("yyyy-MM-dd hh:mm:ss");	
				}else{
					return "";
			};					
		}
		},{
			colkey : "Machine_Number",
			name : "机台号"
		},{
			colkey : "Mold_Number",
			name : "模具号"
		},{
			colkey : "Order_ID",
			name : "订单号"
		},{
			colkey : "Check_No",
			name : "点检项目"
		},{
			colkey : "Inspection_Result",
			name : "检查结果",
			renderData : function(rowindex,data, rowdata, column) {	
				if(data==1){
					return "合格";	
				}else{
					return "不合格";
			};					
		}
		},{
			colkey : "Nonconformity_cause",
			name : "不合格原因分析"
		},{
			colkey : "Unqualified_result",
			name : "不合格处理结果"
		},{
			colkey : "Operation",
			name : "操作行为",
			renderData : function(rowindex,data, rowdata, column) {	
				if(data==1){
					return "装模";	
				}else{
					return "拆模";
			};					
		}
		},{
			colkey : "Status",
			name : "状态"
		},{
			colkey : "",
			name : "操作"
		},],
		jsonUrl : rootPath + '/inspection/assembly_findByPage.shtml',
		dymCol:true,
		checkbox : true,
		serNumber : false
	});
	$("#editFun").click("click", function() {
		editAccount();
	});
	$("#delFun").click("click", function() {
		delAccount();
	});
	
	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();
		grid.setOptions({
			data : searchParams
		});
	});
	
});


function delAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择删除项！！");
		return;
	}
	layer.confirm('是否删除？', function(index) {
		var url = rootPath + '/inspection/assembly_deleteEntity.shtml';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('删除成功');
			grid.loadData();
			
		} else {
			layer.msg('删除失败');
		}
	});

}
function editAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 || cbox == "") {
		layer.msg("只能选中一个");
		return;
	}
	pageii = layer.open({
		title : "编辑订单",
		type : 2,
		area : [ "800px", "100%" ],
		content : rootPath + '/inspection/assembly_edit.shtml?id=' + cbox
	});
}